=begin 
Copyright (c) <2009> <Sheheryar Sewani, Sheysrebellion@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=end

#MoneyTracking sample usage
require 'MoneyTracking'

#known issues
# 1)  get_tags will always return the tags for the main account
# 2)  Periodic not supported for add transaction
# 3)  Edit transaction not supported
# 4)  Get User data not supported

username = ''
password = ''

#connect to Moneytrackin
mt = MoneyTracking::MoneyTrackin.new( MoneyTracking::HttpAuth.new(username, password) )

#list the currencies supported by MoneyTrackin
#mt.currencies.each { |c| puts "Currency: " + c.name + "\tid " + c.id }

#The main account's id is an empty string
accounts = mt.get_accounts()
accounts.each { |a| puts "Account\t" + a.id + "\tName: " +  a.name + " Balance: " + a.balance.to_s}

#Add new account
mt.new_account("Groceries", "USD")
mt.get_accounts.each { |a| puts "Name: " +  a.name + " Balance: " + a.balance.to_s + " \t" + a.id}

#Known issue, Get tags will always return the 
#tags for the main Account
account_id = accounts[1].id
mt.get_tags(accounts[1].id).each { |t| puts "Tag\t" + t.valortag + "\t" + t.totalAmount}

#Add transaction, date must be in "YYYY-MM-DD"
tags = ["personal", "drugmart"]
mt.add_transaction(account_id, "Toilitries", -32.45, "2009-10-08", tags)

transactions = mt.transactions(account_id)
transactions.each {|t| puts "id: " + t.id + " amount " + t.amount.to_s  + " desc " + t.description}

#view tags for a transaction
transactions[0].tags.tag.each { |t| puts t }